package com.hanvon.penenginejni;

import android.graphics.Bitmap;

public class HWPenEngine {

    static {
        try {
            System.loadLibrary("hw_PenEngine");
        } catch (UnsatisfiedLinkError e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static int[] bitmapPixels;

    public static void setBristlDabImage(long engine, Bitmap bitmap) {
        if (null != bitmap && 0 != engine) {

            bitmapPixels = new int[bitmap.getWidth() * bitmap.getHeight()];

            bitmap.getPixels(bitmapPixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());

            setBristlDabImage(engine, bitmap.getWidth(), bitmap.getHeight(), bitmapPixels);
        }
    }

    //初始化引擎 宽高，内存 需要类中保存handle值
    public native static long initialize(int width, int height, int[] pDrawMemory);

    //设置颜色
    public native static void setColor(long engine, byte b, byte g, byte r, byte a);

    //设置笔型粗细
    public native static void setSize(long engine, float size);

    //获取笔型粗细
    public native static float getSize(long engine);

    //填充canvas
    public native static void fillSurface(long engine, int color);

    //切换笔橡皮  brushType 默认为 fletpen;
    public native static void setPenStyle(long engine, int brushType);

    //设置毛笔笔头
    private native static void setBristlDabImage(long engine, int width, int height, int[] bitmapMemory);

    //起笔 mouseDown penDown
    public native static void beginStroke(long engine);

    //运笔 mouseMove penMove
    public native static void strokePoint(long engine, float x, float y, float p, int[] rect);

    //抬笔 mouseUp penUp
    public native static void endStroke(long engine, int[] rect);

    //销毁引擎
    public native static boolean destroyEngine(long engine);

}
